package com.example.product.controler;

import com.example.product.Bean.Product;
import com.example.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

//@RequestMapping("/api/product")
@Slf4j
@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @GetMapping("/product/{id}")
    public Product getProduct(@PathVariable("id") Long productId,
                              @RequestHeader(value = "token", required = false) String token,
                              @RequestHeader(value = "X-Token", required = false) String xToken,
                              HttpServletRequest request) {
        log.info(token);
        log.info("----------------------:" + request.getHeader("X-Token"));
//        try {
//            TimeUnit.SECONDS.sleep(2);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        Product product = productService.getProductById(productId);
        return product;
    }

    @GetMapping("writeDb")
    public String writeDb() {
        log.info("product writeDb");
        return "product writeDb success....";
    }

    @GetMapping("readDb")
    public String readDb() {
        log.info("product readDb");
        return "product readDb success....";
    }


}
